{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "西瓜书习题3.5:编程实现线性判别分析，并给出西瓜数据集3.0α上的结果。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "from numpy import linalg\n",
    "data = np.array([[0.697, 0.774, 0.634, 0.608, 0.556, 0.403, 0.481, 0.437, 0.666, 0.243, 0.245, 0.343, 0.639, 0.657, 0.360, 0.593, 0.719],\n",
    "       [0.460, 0.376, 0.264, 0.318, 0.215, 0.237, 0.149, 0.211, 0.091, 0.267, 0.057, 0.099, 0.161, 0.198, 0.370, 0.042, 0.103]])\n",
    "label=np.array([1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "data = data.T"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([array([[0.697, 0.46 ],\n",
       "       [0.774, 0.376],\n",
       "       [0.634, 0.264],\n",
       "       [0.608, 0.318],\n",
       "       [0.556, 0.215],\n",
       "       [0.403, 0.237],\n",
       "       [0.481, 0.149],\n",
       "       [0.437, 0.211]]),\n",
       "       array([[0.666, 0.091],\n",
       "       [0.243, 0.267],\n",
       "       [0.245, 0.057],\n",
       "       [0.343, 0.099],\n",
       "       [0.639, 0.161],\n",
       "       [0.657, 0.198],\n",
       "       [0.36 , 0.37 ],\n",
       "       [0.593, 0.042],\n",
       "       [0.719, 0.103]])], dtype=object)"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#集合\n",
    "X0 = data[:8]\n",
    "X1 = data[8:]\n",
    "X = np.array([X0,X1])\n",
    "#均值向量\n",
    "u0 = np.mean(X0,axis=0)\n",
    "u1 = np.mean(X1,axis=0)\n",
    "u = np.array([u0, u1])\n",
    "X"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(9, 2)"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X[1].shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.5844474444444444"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'''\n",
    "#类内散度矩阵S_w\n",
    "\n",
    "@para   X：数据集\n",
    "@para   u：均值向量\n",
    "@return S_w：类内散度矩阵S_w\n",
    "'''\n",
    "def S_w(X, u):\n",
    "    M0 = 0.0\n",
    "    M1 = 0.0\n",
    "    for i in range(X[0].shape[0]):\n",
    "        M0 += np.dot(X[0][i]-u[0], (X[0][i]-u[0]).T)\n",
    "    for i in range(X[1].shape[0]):\n",
    "        M0 += np.dot(X[1][i]-u[1], (X[1][i]-u[1]).T)\n",
    "    return M0 + M1\n",
    "S_w = S_w(X,u)\n",
    "S_w"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.02153496450617283"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'''\n",
    "#类间散度矩阵\n",
    "\n",
    "@para   u：均值向量\n",
    "@return S_b：类内散度矩阵S_b\n",
    "'''\n",
    "def S_b(u):\n",
    "    return np.dot(u[0]-u[1], (u[0]-u[1]).T)\n",
    "S_b(u)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.13284152, 0.21306925])"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#公式3.39计算w\n",
    "w = (u[0]-u[1])/S_w\n",
    "w"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAX8AAAD8CAYAAACfF6SlAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAAHzhJREFUeJzt3X2UXXV97/H398zzU5KZnJmzMSQEJCkN0IpGCmmtWKQCV4kojwaY6bI3q7bee5d1Xctd/lFql7deWV3tuq2uyvVhJhAeAkqJD4iKoLUEJKANgkaSFEIk+8xDJpNM5ikz53v/ODs0jTOZk5wzZ5+Hz2st1pyHnb2/P87kk32+e//2NndHRESqSyLuAkREpPgU/iIiVUjhLyJShRT+IiJVSOEvIlKFFP4iIlVI4S8iUoUU/iIiVUjhLyJShWrjLmAuyWTSV65cGXcZIiJl5bnnnht09875livZ8F+5ciXbt2+PuwwRkbJiZq/mspzaPiIiVUjhLyJShRT+IiJVSOEvIlKFFP4iIlVI4S8ic9q8GVauhEQi+3Pz5rgrkkIp2VM9RSRemzfDxo0wNpZ9/uqr2ecAGzbEV5cUhvb8RWRWn/zkfwT/MWNj2del/Cn8RWRWe/ee2utSXhT+IjKrFStO7XUpLwp/EZnVpz8Nzc3/+bXm5uzrUv4U/iIyqw0b4K674KyzwCz78667dLC3UuhsHxGZ04YNCvtKpT1/EZEqpPAXEalCCn8RkSpUkPA3syvNbKeZ7TKz20+y3HVm5ma2thDbFRGR05N3+JtZDfA54CpgDXCzma2ZZbk24L8Dz+S7TRERyU8h9vwvBna5+x53nwLuB9bPstxfA58FJgqwTRERyUMhwn8Z8Npxz/dFr73BzC4Clrv7N062IjPbaGbbzWz7wMBAAUoTEZHZFCL8bZbX/I03zRLA3wEfn29F7n6Xu69197WdnfPefF5ERE5TIcJ/H7D8uOdnAq8f97wNuAB40sx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NLOXgBngf7r7UHxV5yfHMX8c+H9m9jGy7Y+ect6ZM7P7yLbtktFxjL8E6gDc/Z/IHte4GtgFjAF/VNDtl/H/OxEROU3l3PYREZHTpPAXEalCCn8RkSqk8BcRqUIKfxGRKqTwFxGpQgp/EZEqpPAXEalC/x9hw61dm1c1xgAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "#画图显示最终结果\n",
    "import matplotlib.pyplot as plt\n",
    "for i in range(data.shape[0]):\n",
    "    if(label[i]==0):\n",
    "        plt.plot(data[i][0],data[i][1],'r+')\n",
    "    else:\n",
    "        plt.plot(data[i][0],data[i][1],'bo')\n",
    "x = np.linspace(0, 1, 50)\n",
    "y = -w[0]/w[1]*x \n",
    "plt.plot(x,y,'y-')\n",
    "plt.show()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
